<html>
<head><meta charset="utf-8"><title>Issue rust-clippy#4554 · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html">Issue rust-clippy#4554</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="234818193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234818193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boxdot <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234818193">(Apr 16 2021 at 08:57)</a>:</h4>
<p>I believe the issue <a href="https://github.com/rust-lang/rust-clippy/issues/4554">https://github.com/rust-lang/rust-clippy/issues/4554</a> cannot be implemented. Please see my last comment. If there still a way to do it, I am happy to discuss it. :)</p>



<a name="234847038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234847038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234847038">(Apr 16 2021 at 12:51)</a>:</h4>
<p><span class="user-mention" data-user-id="355574">@boxdot</span> maybe you could change the lint only to warn if the body of the loop never modifies the collection the iterator comes from? that might be hard to detect though</p>



<a name="234847460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234847460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boxdot <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234847460">(Apr 16 2021 at 12:54)</a>:</h4>
<p>I think this is impossible to detect statically, since a modification of the collection can be completely implicit. E.g. by having an Rc to the collection, calling a closure which modifies it, etc...</p>



<a name="234847525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234847525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234847525">(Apr 16 2021 at 12:55)</a>:</h4>
<p>oh hmm good point, I hadn't thought about interior mutability</p>



<a name="234847533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234847533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234847533">(Apr 16 2021 at 12:55)</a>:</h4>
<p>or global state</p>



<a name="234848340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234848340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boxdot <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234848340">(Apr 16 2021 at 13:00)</a>:</h4>
<p>Technically, it is possible to cover a special case, where the block does not access any variable outside and does not have breaks.</p>



<a name="234848508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Issue%20rust-clippy%234554/near/234848508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boxdot <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Issue.20rust-clippy.234554.html#234848508">(Apr 16 2021 at 13:01)</a>:</h4>
<p>But even then, there is an example where people do <code>while let Some((_, ch)) = self.chars.clone().next() { break; }</code>. I am not sure why people would do this, though :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>